//! 提供了开发工具宏
//!
//! 用于快速创建 sgs_core::card::Card 类型

/// 生成 Role 的声明宏
#[macro_export]
macro_rules! create_role {
    ($text:expr) => {{
        match ::sgs_core::player::Role::try_from($text) {
            Ok(_v) => _v,
            Err(_e) => panic!("{}", _e),
        }
    }};

    ($sp:expr => $text:expr) => {{
        match ::sgs_core::player::Role::try_from(($text, $sp)) {
            Ok(_v) => _v,
            Err(_e) => panic!("{}", _e),
        }
    }};

    ($($text:expr),+ $(,)?) => {{
        vec![$(create_role!($text)),+]
    }};

    (@split $sp:expr, $($text:expr),+ $(,)?) => {{
        vec![$(create_role!($text)),+]
    }};


    ($($sp:expr => $text:expr),+ $(,)?) => {{
        vec![$(create_role!($sp => $text)),+]
    }};
}

#[cfg(test)]
mod test {

    use sgs_core::player::*;
    #[test]
    fn test_create_role_macro() {
        let card = create_role!(" " => "刘备 4 4 S 男");
        let want = Role {
            hp: 4,
            max_hp: 4,
            name: "刘备".to_string(),
            power: Power::SHU,
            gender: Gender::Male,
            ..Default::default()
        };

        assert_eq!(want, card.clone());
        let card_list = create_role!("刘备/4/4/蜀/男", "刘备/4/4/蜀/男");

        assert_eq!(card_list, vec![card.clone(), card.clone()]);
    }
}
